;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2020 pkill9 <pkill9@runbox.com>
;;; Copyright © 2021 florhizome <florhizome@posteo.net>
;;; Copyright © 2021 (unmatched parenthesis <paren@disroot.org>
;;; Copyright © 2021 jgart <jgart@dismail.de>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages wayfire)
  #:use-module (guix build utils)
  #:use-module (guix build-system meson)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (gnu packages)
  #:use-module (gnu packages admin)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages build-tools)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages image)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages maths)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages pulseaudio)
  #:use-module (gnu packages vulkan)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages xdisorg)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages check)
  #:use-module (gnu packages cmake)
  #:use-module ((guixrus packages freedesktop) #:prefix rus:))

(define-public wf-config
  (let ((commit "e42a3870fb194842a505ad5a9671be1aebda0b0b")
        (version "0.8.0")
        (revision "0"))
    (package
     (name "wf-config")
     (version (git-version version revision commit))
     (source
      (origin
       (method git-fetch)
       (uri
        (git-reference
         (url "https://github.com/WayfireWM/wf-config.git")
         (commit commit)))
       (sha256
        (base32 "0n6i3hizbqixxjh33950ya8avwqil5k94jbgff1pimcbh9ahpgrr"))))
     (build-system meson-build-system)
     (propagated-inputs
      (list glm libevdev libxml2))
     (native-inputs
      (list pkg-config cmake))
     (inputs
      (list rus:wlroots-for-wayfire doctest))
     (home-page "https://wayfire.org")
     (synopsis "A library for managing configuration files for wayfire.")
     (description "@code{wf-config} is wayfire's native configuration backend.")
     (license license:expat))))

;;;TODO make tests work (add doctest + cmake to build them)
(define-public wayfire
  (let ((commit "6720f6a6e902d2a100158b31f611cddb1a2568bd")
        (version "0.8.0")
        (revision "0"))
    (package
      (name "wayfire")
      (version (git-version version revision commit))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/WayfireWM/wayfire.git")
           (commit commit)
           ;;for wf-utils, wf-touch, wf-config and wlroots are built separately
           (recursive? #t)))
         (sha256
          (base32 "12lc5sl93qy2iqp1jbwc8s2krbjs7il04dqz2j5gp4d8lpkhyc67"))))
      (build-system meson-build-system)
      (propagated-inputs
       (list wf-config pango rus:wlroots-for-wayfire))
      (inputs
       (list cairo elogind eudev freetype glm
             libdrm libevdev libinput libjpeg-turbo libpng
             pixman libxkbcommon libxml2 mesa seatd wayland))
      (native-inputs
       (list bash pkg-config wayland-protocols))
      (native-search-paths
       (list
        (search-path-specification
         (variable "WAYFIRE_PLUGINS_DIRECTORY")
         (separator #f)
         (files '("lib/wayfire/plugins")))
        (search-path-specification
         (variable "WAYFIRE_PLUGINS_XML_DIRECTORY")
         (separator #f)
         (files '("$XDG_DATA_DIRS/share/wayfire/metadata")))))
      (search-paths native-search-paths)
      (arguments
       `(#:configure-flags
         (list
          "-Duse_system_wfconfig=disabled"
          "-Dwlroots:logind-provider=elogind")
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'patch-shell-path
             (lambda* (#:key inputs #:allow-other-keys)
               (substitute* "src/meson.build"
                 (("/bin/sh")
                  (string-append (assoc-ref inputs "bash")
                                 "/bin/bash")))
               (substitute* "src/core/core.cpp"
                 (("/bin/sh")
                  (string-append (assoc-ref inputs "bash")
                                 "/bin/bash"))))))))
      (home-page "https://wayfire.org")
      (synopsis "Wayland compositor")
      (description "Wayfire is a wayland compositor based on wlroots.
It aims to create a customizable, extendable and lightweight
 environment without sacrificing its appearance.")
      (license license:expat))))

(define-public wayfire-plugins-extra
  (let ((commit "21b598460fd8c6c1e8e6ff70067df60c9bc9601f")
        (version "0.8.0")
        (revision "0"))
    (package
      (name "wayfire-plugins-extra")
      (version (git-version version revision commit))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/WayfireWM/wayfire-plugins-extra")
           (commit commit)
           (recursive? #t)))
         (sha256
          (base32 "167iiypiqzc6sbkckwxmvkhx9w68dhyiwgyi50dg5il11lpmca0d"))))
      (build-system meson-build-system)
      (arguments
       `(#:glib-or-gtk? #t
         #:configure-flags
         (list
          "-Denable_wayfire_shadows=true")
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'alter-target-dirs
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out")))
                 ;; We have to patch paths of the standard plugins and those
                 ;; found in ./subprojects/projectname/meson.build
                 (substitute*
                     (list
                      "./metadata/meson.build"
                      "./subprojects/dbus/meson.build"
                      "./subprojects/windecor/meson.build"
                      "./subprojects/wayfire-shadows/meson.build")
                   (("wayfire\\.get_variable\\(pkgconfig: 'metadatadir'\\)")
                    (string-append "'" out "/share/wayfire/metadata'")))
                 (substitute*
                     (list
                      "subprojects/windecor/meson.build"
                      "subprojects/wayfire-shadows/meson.build")
                   (("wayfire\\.get_variable\\( pkgconfig: 'metadatadir' \\)")
                    (string-append "'" out "/share/wayfire/metadata'")))
                 (substitute* "subprojects/dbus/meson.build"
                   (("wayfire\\.get_variable\\(pkgconfig: 'plugindir'\\)")
                    (string-append "'" out "/lib/wayfire'"))) #t))))))
      (native-inputs
        (list gobject-introspection pkg-config))
      (inputs
        (list gtkmm-3 librsvg pango wayfire wf-config
              rus:wlroots-for-wayfire))
      (native-search-paths (package-native-search-paths wayfire))
      (search-paths  native-search-paths)
      (home-page "https://wayfire.org")
      (synopsis "Additional plugins for wayfire")
      (description "@code{wayfire-plugins-extra} contains plugins
 that have external dependencies, debugging purposes or otherwise
 will not be included with wayfire core.")
      (license license:expat))))

(define-public wf-shell
  (let ((commit "b60b02a30179609ff553537b5cc0d346cc489408")
        (version "0.8.0")
        (revision "0"))
    (package
      (name "wf-shell")
      (version (git-version version revision commit))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/WayfireWM/wf-shell.git")
           (commit commit)
           (recursive? #t)))
         (sha256
          (base32 "0rsrm5d07yk4yvh8p4ipsgx2rhvl1qpxiqc886hf9ry3s43dzxg1"))))
      (build-system meson-build-system)
      (native-inputs
       (list
        gobject-introspection
        pkg-config))
      (inputs
       (list alsa-lib glib gtk-layer-shell gtkmm-3 libdrm
        pulseaudio wayfire wayland wf-config))
      (native-search-paths (package-native-search-paths wayfire))
      (search-paths  native-search-paths)
      (home-page "https://wayfire.org")
      (synopsis "GTK-based panel for wayfire")
      (description "@code{wf-shell} contains various components
 needed to build a fully functional DE based around wayfire.
 Currently it contains a GTK-based panel, a dock and a background
 wallpaper client.")
      (license license:expat))))

(define-public wcm
  (let ((commit "2b139dc76a01f14340b9daee9ea021330f625460")
        (version "0.8.0")
        (revision "1"))
    (package
      (name "wcm")
      (version (git-version version revision commit))
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/WayfireWM/wcm.git")
           (commit commit)))
         (sha256
          (base32 "0ln1432igiik86d1hv7sqrrmadpcxvxgy0b60zrbv2bnwz41vs9r"))))
      (build-system meson-build-system)
      (arguments `(#:configure-flags '("-Denable_wdisplays=false")))
      (native-inputs (list pkg-config `(,glib "bin") wayland-protocols))
      (inputs (list wf-config wayland wayfire gtk+))
      (propagated-inputs (list rus:wlroots-for-wayfire))
      (home-page "https://wayfire.org")
      (synopsis "Wayfire Config Manager")
      (description "Wayfire Config Manager is a Gtk3 application to
configure wayfire. It writes the config file that wayfire reads to
update option values.")
      (license license:expat))))


(define-public swayfire
  (let ((commit "8c2cda501a4c801406e6361f74c61e0e21ed99d3")
        (revision "0"))
    (package
      (name "swayfire")
      (version "0.1")
      (source
       (origin
         (method git-fetch)
         (uri
          (git-reference
           (url "https://github.com/Javyre/swayfire")
           (commit commit)))
         (sha256
          (base32 "0gjjn7k1qqa8f0fsyyk4qabc3p2w39fx4zcigfsya85xgn587shl"))))
      (build-system meson-build-system)
      (arguments
       `(#:meson ,meson-0.59
         #:phases
         (modify-phases %standard-phases
           (add-after 'unpack 'alter-target-dirs
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out")))
                 (substitute* "./metadata/meson.build"
                   (("wayfire\\.get_variable\\(pkgconfig: 'metadatadir'\\)")
                    (string-append "'" out "/share/wayfire/metadata'")))
                 (substitute* "./src/meson.build"
                   (("wayfire\\.get_variable\\(pkgconfig: 'plugindir'\\)")
                    (string-append "'" out "/lib/wayfire'")))))))))
      (native-inputs
       (list pkg-config))
      (inputs
       (list rus:wlroots-for-wayfire wf-config libxml2 wayland wayfire cairo))
      (native-search-paths (package-native-search-paths wayfire))
      (search-paths  native-search-paths)
      (synopsis "Tiling window manager plugin for wayfire")
      (description "Swayfire is a tiling window manager for Wayfire, inspired by
i3/sway.  It aims to improve upon sway/i3wm features as a plugin for the Wayfire
compositor.")
      (home-page "https://github.com/Javyre/swayfire")
      (license license:gpl3+))))
